from flask import Flask
import datetime
import time
import random
from container import Container
from flask import request

app = Flask(__name__)
# sockets = Sockets(app)
# 路由器容器，实际业务处理
c = Container()


# 获取历史输出
@app.route('/allOutput')
def allOutput():
    return c.all_output();

# 初始化拓扑
@app.route('/initTopology')
def initTopology():
    rId = request.args.get('rId')
    res = c.init_topology(rId)
    return res;

# 配置acl
@app.route('/configAcl')
def configAcl():
    rId = request.args.get('rId')
    res = c.config_acl(rId);
    return res;

# 取消配置acl
@app.route('/noConfigAcl')
def noConfigAcl():
    rId = request.args.get('rId')
    res = c.no_config_acl(rId);
    return res;

# 检查acl
@app.route('/checkAcl')
def checkAcl():
    rId = request.args.get('rId')
    res = c.check_acl(rId);
    return res;


if __name__ == "__main__":
    from gevent import pywsgi
    server = pywsgi.WSGIServer(('127.0.0.1', 5000), app)
    print('server start')
    server.serve_forever()
